<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>设置/获取断言的各种标志</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.assert-options" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">assert_options</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">assert_options</span> &mdash; <span class="dc-title">设置/获取断言的各种标志</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.assert-options-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>assert_options</strong></span>
    ( <span class="methodparam"><span class="type">int</span> <code class="parameter">$what</code></span>
   [, <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$value</code></span>
  ] ) : <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span></div>

  <p class="para rdfs-comment">
   设置 <span class="function"><a href="assert.html" class="function">assert()</a></span> 的各种控制选项，或者是仅仅查询当前的设置。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.assert-options-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">what</code></dt>

     <dd>

      <p class="para">
       <table class="doctable table">
        <caption><strong>断言标志</strong></caption>
        
         <thead>
          <tr>
           <th>标志</th>
           <th>INI 设置</th>
           <th>默认值</th>
           <th>描述</th>
          </tr>

         </thead>

         <tbody class="tbody">
          <tr>
           <td>ASSERT_ACTIVE</td>
           <td>assert.active</td>
           <td>1</td>
           <td>启用 <span class="function"><a href="assert.html" class="function">assert()</a></span> 断言</td>
          </tr>

          <tr>
           <td>ASSERT_WARNING</td>
           <td>assert.warning</td>
           <td>1</td>
           <td>为每个失败的断言产生一个 PHP 警告（warning）</td>
          </tr>

          <tr>
           <td>ASSERT_BAIL</td>
           <td>assert.bail</td>
           <td>0</td>
           <td>在断言失败时中止执行</td>
          </tr>

          <tr>
           <td>ASSERT_QUIET_EVAL</td>
           <td>assert.quiet_eval</td>
           <td>0</td>
           <td>
            在断言表达式求值时禁用 error_reporting
           </td>
          </tr>

          <tr>
           <td>ASSERT_CALLBACK</td>
           <td>assert.callback</td>
           <td>(<strong><code>NULL</code></strong>)</td>
           <td>断言失败时调用回调函数</td>
          </tr>

         </tbody>
        
       </table>

      </p>
     </dd>

    
    
     <dt>
<code class="parameter">value</code></dt>

     <dd>

      <p class="para">
       标志的新值。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.assert-options-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   返回任意标志的原始设置，出错时返回 <strong><code>FALSE</code></strong>。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.assert-options-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-484">
   <p><strong>Example #1 <span class="function"><strong>assert_options()</strong></span> 例子</strong></p>
   <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;处理断言失败时的函数<br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">assert_failure</span><span style="color: #007700">()<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'Assert&nbsp;failed'</span><span style="color: #007700">;<br />}<br /><br /></span><span style="color: #FF8000">//&nbsp;我们的测试函数<br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">test_assert</span><span style="color: #007700">(</span><span style="color: #0000BB">$parameter</span><span style="color: #007700">)<br />{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">assert</span><span style="color: #007700">(</span><span style="color: #0000BB">is_bool</span><span style="color: #007700">(</span><span style="color: #0000BB">$parameter</span><span style="color: #007700">));<br />}<br /><br /></span><span style="color: #FF8000">//&nbsp;设置断言标志<br /></span><span style="color: #0000BB">assert_options</span><span style="color: #007700">(</span><span style="color: #0000BB">ASSERT_ACTIVE</span><span style="color: #007700">,&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">assert_options</span><span style="color: #007700">(</span><span style="color: #0000BB">ASSERT_BAIL</span><span style="color: #007700">,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">assert_options</span><span style="color: #007700">(</span><span style="color: #0000BB">ASSERT_WARNING</span><span style="color: #007700">,&nbsp;&nbsp;</span><span style="color: #0000BB">false</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">assert_options</span><span style="color: #007700">(</span><span style="color: #0000BB">ASSERT_CALLBACK</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'assert_failure'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;让一个断言会失败<br /></span><span style="color: #0000BB">test_assert</span><span style="color: #007700">(</span><span style="color: #0000BB">1</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;由于&nbsp;ASSERT_BAIL&nbsp;是&nbsp;true，这里永远也到不了<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">'Never&nbsp;reached'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.assert-options-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="assert.html" class="function" rel="rdfs-seeAlso">assert()</a> - 检查一个断言是否为 FALSE</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>